package Encryption;

import java.math.BigInteger;

public final class DH 
{
	public static final DH base_4 = new DH(BigInteger.valueOf(4));
	private final BigInteger base;
	private static final BigInteger mod = BigInteger.valueOf(11);
	
	public DH(BigInteger base)
	{
		this.base = base;
	}
	
	public int GetPublicKey(int privateKey)
	{
		BigInteger num = BigInteger.valueOf(privateKey);
		BigInteger publicKey = base.modPow(num, mod);
		return publicKey.intValue();
	}
	
	public static int GetSessionKey(int privateKey, int responseKey)
	{
		BigInteger response = BigInteger.valueOf(responseKey);
		BigInteger exponent = BigInteger.valueOf(privateKey);
		
		BigInteger sharedKey = response.modPow(exponent, mod);
		
		return sharedKey.intValue();
	}
}
